package com.strato.quartz.v1_0_0.schedule.jobstore.tx;

import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import org.quartz.utils.ConnectionProvider;

import com.strato.jdbc.datasource.v1_0_0.DataSourceFactory;

public class DataSourceConnectionProvider implements ConnectionProvider {

	private String dataSourceName;
	
	public String getDataSourceName() {
		return dataSourceName;
	}

	public void setDataSourceName(String dataSourceName) {
		this.dataSourceName = dataSourceName;
	}

	@Override
	public Connection getConnection() throws SQLException {
		DataSource dataSource = DataSourceFactory.getInstance().getDataSource(dataSourceName);
		if(dataSource==null){
			throw new RuntimeException("No Datasource Found:"+dataSourceName);
		}
		return dataSource.getConnection();
	}

	@Override
	public void initialize() throws SQLException {
	}

	@Override
	public void shutdown() throws SQLException {
	}

}
